#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import multiprocessing
import time


def myprint(obj):
    sys.stdout.write(str(obj) + '\n')


def slow_worker():
    myprint('Starting worker')
    time.sleep(0.1)
    myprint('Finished worker')


if __name__ == '__main__':
    p = multiprocessing.Process(target=slow_worker)
    myprint('BEFORE: %s %s' % (p, p.is_alive()))

    p.start()
    myprint('DURING: %s %s' % (p, p.is_alive()))

    # 可以把下面两句注释看看结果是什么样

    p.terminate()
    myprint('TERMINATED: %s %s' % (p, p.is_alive()))

    p.join()
    myprint('JOINED: %s %s' % (p, p.is_alive()))
